﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SBACN.WebSite.Code;
using System.Linq.Expressions;
using SBACN.WebSite.Models;


namespace SBACN.WebSite.Admin.GuildMsg
{
	public partial class MonthlyEvenEdit : BasePage
	{
		/// <summary>
		/// 系统字典类型
		/// </summary>
		public string SystemType
		{
			get
			{
				//if (ViewState["SystemType"] == null)
				//    return "00020003";//默认值
				//else
				//    return ViewState["SystemType"].ToString();
				return this.SystemCode;
			}
			private set
			{
				ViewState["SystemType"] = this.SystemCode;
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!AdminBasePage.CheckCodeRight(AdminBasePage.AdminInfo, SystemType))
			{
				AdminBasePage.RedirectWithMessage(AdminDefaultPage, "您没有访问当前页面的权限,请与系统管理员联系!");
				return;
			}

			string MEID = Request.QueryString["meid"];
			this.HidMEID.Value = MEID;
			if (!IsPostBack && !string.IsNullOrWhiteSpace(MEID))
			{
				ShowMECon(MEID);
			}
		}

		protected void ShowMECon(string MEID)
		{
			int id = Convert.ToInt32(MEID);
			TB_MonthlyEvents resultME = DAL.DALHelper.Instance.GetObject<TB_MonthlyEvents>("ID", id);
			//this.METitle.Text = resultME.Title;
			this.MEDate.Text = resultME.EventDate.ToString("yyyy-MM-dd");
			//this.Address.Text = resultME.Address;
			this.Event.Text = resultME.Description;
			//this.Start.Text = resultME.StartHour.ToString();
			//this.End.Text = resultME.EndHour.ToString();
		}

		protected void SubBtn_Click(object sender, EventArgs e)
		{
			if (string.IsNullOrWhiteSpace(this.HidMEID.Value))
			{//creat
				TB_MonthlyEvents NewObjME = DAL.DALHelper.Instance.Create<TB_MonthlyEvents>();
				NewObjME.CreateBy = AdminBasePage.AdminInfo.UserName;
				NewObjME.CreateDate = DateTime.Now;
				//NewObjME.Title = this.METitle.Text;
				NewObjME.EventDate = Convert.ToDateTime(this.MEDate.Text);
				//NewObjME.Address = this.Address.Text;
				NewObjME.Description = this.Event.Text;
				//string SH = this.StartH.SelectedValue;
				//string SM = this.StartM.SelectedValue;
				//string EH = this.EndHour.SelectedValue;
				//string EM = this.EndM.SelectedValue;
				//NewObjME.StartHour = SH + ":" + SM + ":00";
				//NewObjME.EndHour = EH + ":" + EM + ":00";
				DAL.DALHelper.Instance.Add<TB_MonthlyEvents>(NewObjME);
			}
			else
			{//update
				int id = Convert.ToInt32(this.HidMEID.Value);
				TB_MonthlyEvents resultME = DAL.DALHelper.Instance.GetObject<TB_MonthlyEvents>("ID", id);
				//resultME.Title = this.METitle.Text;
				resultME.EventDate = Convert.ToDateTime(this.MEDate.Text);
				//resultME.Address = this.Address.Text;
				resultME.Description = this.Event.Text;
				//string SH = this.StartH.SelectedValue;
				//string SM = this.StartM.SelectedValue;
				//string EH = this.EndHour.SelectedValue;
				//string EM = this.EndM.SelectedValue;
				//NewObjME.StartHour = Convert.ToDateTime(SH + ":" + SM + ":00");
				//NewObjME.EndHour = Convert.ToDateTime(EH + ":" + EM + ":00");
				DAL.DALHelper.Instance.Update<TB_MonthlyEvents>(resultME);
			}
			DAL.DALHelper.Instance.SaveChanges();
			RefreshNewsList();
		}

		private void RefreshNewsList()
		{
			string clientJs = "<script type=\"text/javascript\" language=\"javascript\">";
			clientJs += "if(window.opener && window.opener.RefreshNewsList) window.opener.RefreshNewsList();";
			clientJs += "window.close();</script>";
			Response.Write(clientJs);
			Response.End();
		}
	}
}